package com.frank.libandroid.util;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;

public class TextWatcherUtil {
    public static void setTextWatchEnable(View view, EditText... editTexts) {
        TextWatcher textWatcher = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                boolean ok = true;
                for (EditText editText : editTexts) {
                    if (editText.getText().toString().isEmpty()) {
                        ok = false;
                        break;
                    }
                }
                view.setEnabled(ok);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        };
        for (EditText editText : editTexts) {
            editText.addTextChangedListener(textWatcher);
        }
    }
}
